<td>@Html.DropDownList("Departments", newList<SelectListItem>
{
newSelectListItem { Text = "IT", Value = "1", Selected=true},
newSelectListItem { Text = "Account", Value = "2"},
newSelectListItem { Text = "Sales", Value = "3"},
newSelectListItem { Text = "HR", Value = "4"}
}, "Select Department")
<!DOCTYPEhtml>
<!DOCTYPE html>
<html>
<head>
<title>Employee Form</title>
<h2>Employee Registration</h2>
</head>
<body>
<style>
table, th, td
{
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd)
{
background-color: #ffe6e6;
}
table tr:nth-child(even)
{
background-color: #ccffcc;
}
</style>
@using (Html.BeginForm())
{
<table style="font-family:Arial; font-size:medium; color:darkblue">
<tr>
<td><b>Employee ID</b></td>
<td>@Html.TextBox("txtID")</td>
</tr>
<tr>
<td><b>Employee Name</b></td>
<td>@Html.TextBox("txtName")</td>
</tr>
<tr>
<td><b>Password</b></td>
<td>@Html.Password("txtPassword")</td>
</tr>
<tr>
<td><b>Gender</b></td>
<td>Male: @Html.RadioButton("rdbMale", "Male", false) FeMale: @Html.RadioButton("rdbFeMale",false)</td>
</tr>
<tr>
<td><b>Department</b></td>
<td>@Html.DropDownList("Departments", new List<SelectListItem>
{
new SelectListItem { Text = "IT", Value = "1", Selected=true},
new SelectListItem { Text = "Account", Value = "2"},
new SelectListItem { Text = "Sales", Value = "3"},
new SelectListItem { Text = "HR", Value = "4"}
}, "Select Department")
</td>
</tr>
<tr>
<td><b>Language Known</b></td>
<td> Hindi :@Html.CheckBox("Hindi")<br />
English :@Html.CheckBox("English")<br>
Marathi :@Html.CheckBox("Marathi")<br>
</td>
</tr>
<tr>
<td><b>Address</b></td>
<td>@Html.TextArea("Comments", "", 5, 25, null)</td>
</tr>
</table>
<br /><br />
<input type="submit" value="Register" />
}
</body>
</html>
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Mvc;
usingMvcDDL.Models;
namespaceMvcDDL.Controllers
{
publicclassHomeController : Controller
{
publicActionResult Index()
{
EmployeeDBContextdb = newEmployeeDBContext();
ViewBag.Departments = newSelectList(db.Departments, "DEPID", "DepName");
return View();
}
}
}
@{
ViewBag.Title = "Select Department";
}
<h2>Select Department</h2>
@Html.DropDownList("Departments", "Select Department")